<?php
/**
 * Created by PhpStorm.
 * User: stupboy
 * Date: 2018/2/8
 * Time: 16:39
 */

namespace app\api\controller\passenger;

class Base extends \app\api\controller\Base
{
    /**
     * 成功返回
     */
    public function retSucc($data=array(),$msg='ok',$code=1){
        $info['code'] = $code;
        $info['msg']  = $msg;
        $info['time'] = time();
        $info         = array_merge($info,$data);
        return json($info);
    }

    /**
     * 失败返回
     */
    public function retError($msg='',$code=0){
        $info['code'] = $code;
        $info['msg']  = intval($msg)>99 ? $this->getErrorMsg($msg) : $msg;
        $info['time'] = time();
        return json($info);
    }

    /**
     * 错误信息代码转换
     * @param int $code
     * @return string
     */
    public function getErrorMsg($code=100){
        $errorArr = \think\Config::get('error_msg');
        return isset($errorArr[$code]) ? $errorArr[$code] : 'undefine';
    }
}